package framework.util.codeset.service.impl;

import framework.util.codeset.bo.SysCodeset;
import framework.util.codeset.bo.SysCodesetDetail;
import framework.util.codeset.dao.ISysCodesetDao;
import framework.util.codeset.service.SysCodesetDetailService;
import framework.util.codeset.service.SysCodesetService;
import framework.util.queryFilter.service.impl.IBaseServiceImpl;
import framework.util.queryFilter.service.impl.QueryFilter;
import framework.util.queryFilter.vo.Where;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.util.List;

@Service("SysCodesetService")
public class SysCodesetServiceImpl extends IBaseServiceImpl<SysCodeset, Integer> implements SysCodesetService {

    @Resource
    private ISysCodesetDao dao;
    @Resource
    private SysCodesetDetailService codesetDetailService;

    @Transactional(rollbackOn = Exception.class)
    @Override
    public void removeBoAndDetail(Integer lid) {
        //先删除明细
        QueryFilter filter = new QueryFilter(1, Integer.MAX_VALUE);
        filter.where(SysCodesetDetail.CLID, Where.eq, lid);
        List<SysCodesetDetail> list = codesetDetailService.getAll(filter);
        if(!CollectionUtils.isEmpty(list)){
            codesetDetailService.removeBatch(list);
        }

        //在删除主表
        this.removeById(lid);
    }


}

